package cc.rengu.igas.bomp.core.service.trans;

import cc.rengu.igas.acct.facade.base.Header;
import cc.rengu.igas.acct.facade.request.VirtAcctPreAuthCancelRequest;
import cc.rengu.igas.acct.facade.request.VirtAcctPreAuthCompRequest;
import cc.rengu.igas.acct.facade.request.VirtAcctSingleAdjustRequest;
import cc.rengu.igas.acct.facade.response.VirtAcctPreAuthCancelResponse;
import cc.rengu.igas.acct.facade.response.VirtAcctPreAuthCompResponse;
import cc.rengu.igas.acct.facade.response.VirtAcctSingleAdjustResponse;
import cc.rengu.igas.bomp.common.constant.DubboMethodConstant;
import cc.rengu.igas.bomp.common.dao.ManualErrAdjustTxnMapper;
import cc.rengu.igas.bomp.common.dao.ManualReconErrTxnMapper;
import cc.rengu.igas.bomp.common.dao.impl.ManualErrAdjustTxnMapperImpl;
import cc.rengu.igas.bomp.common.dao.impl.ManualReconErrTxnMapperImpl;
import cc.rengu.igas.bomp.common.entity.ErrAdjustTxn;
import cc.rengu.igas.bomp.common.entity.ReconErrTxn;
import cc.rengu.igas.bomp.common.enums.*;
import cc.rengu.igas.bomp.core.service.base.PayService;
import cc.rengu.igas.bomp.facade.request.ManualAdjustmentRequest;
import cc.rengu.igas.bomp.facade.response.ManualAdjustmentResponse;
import cc.rengu.igas.channel.upac.facade.request.TokenConsumeRefundRequest;
import cc.rengu.igas.channel.upac.facade.response.TokenConsumeRefundResponse;
import cc.rengu.igas.momp.facade.bean.TxnDataRegulationBean;
import cc.rengu.igas.momp.facade.request.TxnDataRegulationRequest;
import cc.rengu.igas.momp.facade.response.TxnDataRegulationResponse;
import cc.rengu.igas.share.common.util.GlobalEsbUtil;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.service.common.constant.TreeNodeConstant;
import cc.rengu.oltp.service.common.dao.MchntOrderInfoMapper;
import cc.rengu.oltp.service.common.dao.PayOrderInfoMapper;
import cc.rengu.oltp.service.common.dao.UserOrderInfoMapper;
import cc.rengu.oltp.service.common.dao.impl.MchntOrderInfoMapperImpl;
import cc.rengu.oltp.service.common.dao.impl.PayOrderInfoMapperImpl;
import cc.rengu.oltp.service.common.dao.impl.UserOrderInfoMapperImpl;
import cc.rengu.oltp.service.common.entity.MchntOrderInfo;
import cc.rengu.oltp.service.common.entity.PayOrderInfo;
import cc.rengu.oltp.service.common.entity.UserOrderInfo;
import cc.rengu.oltp.service.common.enums.ChannelEnum;
import cc.rengu.oltp.service.common.enums.OltpRpcdEnum;
import cc.rengu.oltp.service.model.BizException;
import cc.rengu.oltp.service.model.BizResponse;
import cc.rengu.oltp.service.realize.DubboService;
import cc.rengu.oltp.service.realize.OrderService;
import cc.rengu.oltp.service.realize.impl.DubboServiceImpl;
import cc.rengu.oltp.service.realize.impl.OrderServiceImpl;
import cc.rengu.oltp.utility.util.*;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/*
 * 手工调账服务
 * Created by xubh on 2020/6/3
 */
public class ManualAdjustmentService extends PayService {
    @Override
    protected Object bizBeforeCust() throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        ManualAdjustmentRequest manualAdjustmentRequest = new ManualAdjustmentRequest();
        ConvertUtil.convertOutput(manualAdjustmentRequest);
        return manualAdjustmentRequest;
    }

    @Override
    protected BizResponse bizProcessCust(Object request) throws Exception {
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        ManualAdjustmentRequest manualAdjustmentRequest = (ManualAdjustmentRequest) request;
        ManualAdjustmentResponse manualAdjustmentResponse = new ManualAdjustmentResponse();
        BeanUtil.beanCopy(manualAdjustmentRequest, manualAdjustmentResponse);
        /*根据调账唯一KEY,查询第三方差错交易表*/
        String adjustUnionKey = manualAdjustmentRequest.getAdjustUnionKey();
        String instId = manualAdjustmentRequest.getHeader().getInstId();

        /*必填性校验*/
        if (StringUtil.isEmptyOrNull(adjustUnionKey)) {
            rglog.error("必填性校验失败!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
        ManualReconErrTxnMapper manualReconErrTxnMapper = new ManualReconErrTxnMapperImpl();
        ReconErrTxn reconErrTxn = manualReconErrTxnMapper.selectReconErrTxnByprimaryKey(adjustUnionKey);
        /*是否有数据校验*/
        if (null == reconErrTxn || AdjustStatusEnum.SUCCESS.getJustStatus().equals(reconErrTxn.getAdjustStatus())) {
            rglog.error("获取对账不平信息不存在，不允许发起调账请求，instId:<{}>,adjustUnionKey:<{}>", manualAdjustmentRequest.getHeader().getInstId(), adjustUnionKey);
            throw new BizException(RespCodeEnum.RECORD_NOT_FOUND.getRespCode(), RespCodeEnum.RECORD_NOT_FOUND.getRespDesc());
        }
        /*对账渠道*/
        String prodType = reconErrTxn.getBizProdType();
        /*虚拟账户调账*/
        if (TppsErrTxnProdTypeEnum.VIRTUAL_ACCOUNT.getProdType().equals(prodType)) {

            manualAdjustmentResponse = virtualAccount(manualAdjustmentRequest, reconErrTxn);

            /*营销对账*/
        } else if (TppsErrTxnProdTypeEnum.MARKETING.getProdType().equals(prodType)) {

            /*添加差错调账流水*/
            manualAdjustmentResponse = marketing(manualAdjustmentRequest, reconErrTxn);

            /*银联全渠道代付*/
        } else if (TppsErrTxnProdTypeEnum.UNIONPAY_PARTIALLY_REPAY.getProdType().equals(prodType)
                || TppsErrTxnProdTypeEnum.UNIONPAY_PARTIALLY_COLLECT.getProdType().equals(prodType)
                || TppsErrTxnProdTypeEnum.SHENZHEN_UNIONPAY.getProdType().equals(prodType)
                || TppsErrTxnProdTypeEnum.XIAMEN_UNIONPAY.getProdType().equals(prodType)
        ) {
            /*是否走二次充值转账或消费退货*/
            String status = manualAdjustmentRequest.getStatus();
            if (StringUtil.isEmptyOrNull(status)) {
                manualAdjustmentResponse = unionpayPartiallyRepay(manualAdjustmentRequest, reconErrTxn);
            } else {
                manualAdjustmentResponse = coreGeneralAcctTransferAndConsumeRefund(manualAdjustmentRequest, reconErrTxn);
            }

            /*银联全渠道代收*/
        } else {
            rglog.error("获取对账类型，不允许发起调账请求，prodType:<{}>", manualAdjustmentRequest.getHeader().getInstId(), prodType);
            throw new BizException(RespCodeEnum.RECORD_NOT_FOUND.getRespCode(), RespCodeEnum.RECORD_NOT_FOUND.getRespDesc());

        }
        /* 设置返回参数 */
        BizResponse bizResponse = new BizResponse();
        bizResponse.setRspSysId(ChannelEnum.BOMP.getChannelType());
        bizResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        bizResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());
        bizResponse.setResult(manualAdjustmentResponse);
        return bizResponse;
    }


    @Override
    protected void bizAfterCust(Object response) throws Exception {
        BizResponse bizResponse = (BizResponse) response;
        ManualAdjustmentResponse manualAdjustmentResponse = (ManualAdjustmentResponse) bizResponse.getResult();
        ConvertUtil.convertInput(manualAdjustmentResponse);
    }


    /*
     * 虚拟账户调账
     * @param manualAdjustmentRequest 请求
     * @param reconErrTxn             对账不平表
     * @throws Exception 异常
     */
    private ManualAdjustmentResponse virtualAccount(ManualAdjustmentRequest manualAdjustmentRequest, ReconErrTxn reconErrTxn) throws Exception {
        ManualAdjustmentResponse manualAdjustmentResponse = new ManualAdjustmentResponse();
        String transactionType = reconErrTxn.getTxnNum().substring(1, 3);
        String adjustUnionKey = manualAdjustmentRequest.getAdjustUnionKey();
        String instId = manualAdjustmentRequest.getHeader().getInstId();
        String adjustStatus = reconErrTxn.getAdjustStatus();

        //判断对账结果
        if (ReconRsltEnum.RECONRSLT_02.getReconRslt().equals(reconErrTxn.getReconRslt())) {

            /*未调，失败的反向交易--调用撤销交易*/
            if (AdjustTransactionTypeEnum.back.getTransactionType().equals(transactionType)) {

                /*调账不平表数据修改为调账中*/
                reconErrTxn.setAdjustStatus(AdjustStatusEnum.IN.getJustStatus());
                ManualReconErrTxnMapper manualReconErrTxnMapper = new ManualReconErrTxnMapperImpl();
                int iReturnCode = manualReconErrTxnMapper.updateReconErrTxnByprimaryKey(reconErrTxn);
                if (0 != iReturnCode) {
                    throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
                }

                /*报文头*/
                VirtAcctPreAuthCancelRequest virtAcctPreAuthCancelRequest = new VirtAcctPreAuthCancelRequest();
                virtAcctPreAuthCancelRequest.setHeader(new Header());
                BeanUtil.beanCopy(manualAdjustmentRequest.getHeader(), virtAcctPreAuthCancelRequest.getHeader());
                virtAcctPreAuthCancelRequest.getHeader().setSrcSysId(ChannelEnum.BOMP.getChannelType());  //本系统标识
                virtAcctPreAuthCancelRequest.getHeader().setChanlId(ChannelEnum.BOMP.getChannelType()); //渠道标识
                String traceNo = GlobalEsbUtil.generateEsbSeqeuenceNumber(manualAdjustmentRequest.getHeader().getInstId());
                virtAcctPreAuthCancelRequest.getHeader().setTraceNo(traceNo); //流水号
                virtAcctPreAuthCancelRequest.getHeader().setTxnNum("P06AT300"); //P06AT300
                virtAcctPreAuthCancelRequest.getHeader().setBizType("00"); //业务分类

                virtAcctPreAuthCancelRequest.setUserId(reconErrTxn.getMchntNo());
                virtAcctPreAuthCancelRequest.setUserType("00");
                virtAcctPreAuthCancelRequest.setAcctType("00");
                virtAcctPreAuthCancelRequest.setTransAmt(reconErrTxn.getTransAmt());
                virtAcctPreAuthCancelRequest.setFreezeAcctSeqNum(reconErrTxn.getPayChannelSeqNum());

                //调用撤销交易
                DubboService dubboService = new DubboServiceImpl();
                cc.rengu.igas.acct.facade.result.Result<VirtAcctPreAuthCancelResponse> result = (cc.rengu.igas.acct.facade.result.Result<VirtAcctPreAuthCancelResponse>) dubboService.callDubboService(DubboMethodConstant.DUBBO_VIRT_ACCT_SERVICE, "virtAcctPreAuthCancel", virtAcctPreAuthCancelRequest);

                if (result != null && result.isSuccess()) {
                    if (result.getResult().getRespCode().equals(OltpRpcdEnum.BIZ_PROCESS_TIMEOUT.getRespCode())) {

                        /*更新对账不平交易表*/
                        updateManualReconErrTxn(traceNo, AdjustStatusEnum.OVERTIME.getJustStatus(), reconErrTxn);

                        /*添加差错调账流水*/
                        insertManualErrAdjustTxn(reconErrTxn, null, null, traceNo, null, AdjustStatusEnum.OVERTIME.getJustStatus());

                        rglog.error("手工调账处理超时，instId:<{}>,instId:<{}>", instId, adjustUnionKey);
                        throw new BizException(OltpRpcdEnum.BIZ_PROCESS_TIMEOUT.getRespCode(), OltpRpcdEnum.BIZ_PROCESS_TIMEOUT.getRespDesc());

                    } else {

                        String respCode = result.getResult().getRespCode();
                        String respDesc = result.getResult().getRespDesc();
                        String seqNum = result.getResult().getAcctSeqNum();
                        String acctDate = result.getResult().getAcctDate();
                        String justStatus = (RespCodeEnum.TRANS_SUCCESS.getRespCode().equals(respCode)) ? AdjustStatusEnum.SUCCESS.getJustStatus() : AdjustStatusEnum.FAIL.getJustStatus();

                        manualAdjustmentResponse.setAcctStatus(justStatus);
                        manualAdjustmentResponse.setFailureReason(respDesc);
                        manualAdjustmentResponse.setAcctSeqNum(traceNo);
                        manualAdjustmentResponse.setAcctDate(acctDate);
                        manualAdjustmentResponse.setRespCode(respCode);
                        manualAdjustmentResponse.setRespDesc(respDesc);

                        /*更新对账不平交易表*/
                        updateManualReconErrTxn(traceNo, justStatus, reconErrTxn);

                        /*添加差错调账流水*/
                        String acctStatus = (RespCodeEnum.TRANS_SUCCESS.getRespCode().equals(respCode)) ? AcctStatusEnum.SUCCESS.getAcctStatus() : AcctStatusEnum.FAIL.getAcctStatus();
                        insertManualErrAdjustTxn(reconErrTxn, respCode, respDesc, traceNo, acctDate, acctStatus);

                    }
                } else {

                    /*更新对账不平交易表*/
                    updateManualReconErrTxn(traceNo, AdjustStatusEnum.FAIL.getJustStatus(), reconErrTxn);

                    /*添加差错调账流水*/
                    insertManualErrAdjustTxn(reconErrTxn, null, null, traceNo, null, AcctStatusEnum.FAIL.getAcctStatus());

                    rglog.error("手工调账(调用duboo)处理失败，instId:<{}>,instId:<{}>", instId, adjustUnionKey);
                    throw new BizException(OltpRpcdEnum.BIZ_PROCESS_TIMEOUT.getRespCode(), OltpRpcdEnum.BIZ_PROCESS_TIMEOUT.getRespDesc());

                }

            } else {

                rglog.error("获取对账不平信息状态或交易类型不匹配，不允许发起调账请求，instId:<{}>,adjustUnionKey:<{}>,adjustStatus:<{}>,transactionType:<{}>", manualAdjustmentRequest.getHeader().getInstId(), adjustUnionKey, adjustStatus, transactionType);
                throw new BizException(RespCodeEnum.RECORD_NOT_FOUND.getRespCode(), RespCodeEnum.RECORD_NOT_FOUND.getRespDesc());

            }

            /*支付平台多，通道无的交易*/
        } else if (ReconRsltEnum.RECONRSLT_03.getReconRslt().equals(reconErrTxn.getReconRslt())) {

            //未对账并且正向交易---调用虚拟账户单笔记账
            if (AdjustTransactionTypeEnum.just.getTransactionType().equals(transactionType)
                    || AdjustTransactionTypeEnum.just_01.getTransactionType().equals(transactionType)) {

                /*调账不平表数据修改为调账中*/
                reconErrTxn.setAdjustStatus("01");
                ManualReconErrTxnMapper manualReconErrTxnMapper = new ManualReconErrTxnMapperImpl();
                int iReturnCode = manualReconErrTxnMapper.updateReconErrTxnByprimaryKey(reconErrTxn);
                if (0 != iReturnCode) {
                    throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
                }

                /*调用虚拟账户正向记账接口补记账*/
                VirtAcctSingleAdjustRequest virtAcctSingleAdjustRequest = new VirtAcctSingleAdjustRequest();
                /*报文头*/
                virtAcctSingleAdjustRequest.setHeader(new Header());
                BeanUtil.beanCopy(manualAdjustmentRequest.getHeader(), virtAcctSingleAdjustRequest.getHeader());
                virtAcctSingleAdjustRequest.getHeader().setSrcSysId(ChannelEnum.BOMP.getChannelType());  //本系统标识
                virtAcctSingleAdjustRequest.getHeader().setChanlId(ChannelEnum.BOMP.getChannelType()); //渠道标识
                String traceNo = GlobalEsbUtil.generateEsbSeqeuenceNumber(manualAdjustmentRequest.getHeader().getInstId());
                virtAcctSingleAdjustRequest.getHeader().setTraceNo(traceNo); //流水号
                virtAcctSingleAdjustRequest.getHeader().setTxnNum("P01AT001");
                virtAcctSingleAdjustRequest.getHeader().setBizType("00"); //业务分类
                virtAcctSingleAdjustRequest.getHeader().setTransDate(DateUtil.getCurrentDateTime("yyyyMMdd"));
                virtAcctSingleAdjustRequest.getHeader().setTransTime(DateUtil.getCurrentDateTime("HHmmss"));

                /*外部客户唯一标识*/
                virtAcctSingleAdjustRequest.setUserId(reconErrTxn.getMchntNo());
                /*外部客户类型*/
                virtAcctSingleAdjustRequest.setUserType("00");
                /*账户类型*/
                virtAcctSingleAdjustRequest.setAcctType("00");
                /*交易金额*/
                virtAcctSingleAdjustRequest.setTransAmt(reconErrTxn.getTransAmt());
                /*摘要*/
                virtAcctSingleAdjustRequest.setSummary("记账");
                /*借贷标志*/
                virtAcctSingleAdjustRequest.setDebitCreditFlag("C");

                DubboService dubboService = new DubboServiceImpl();

                //虚拟账户单笔记账
                cc.rengu.igas.acct.facade.result.Result<VirtAcctSingleAdjustResponse> result = (cc.rengu.igas.acct.facade.result.Result<VirtAcctSingleAdjustResponse>) dubboService.callDubboService(DubboMethodConstant.DUBBO_VIRT_ACCT_SERVICE, "virtAcctSingleAdjust", virtAcctSingleAdjustRequest);

                if (result != null && result.isSuccess()) {
                    if (result.getResult().getRespCode().equals(OltpRpcdEnum.BIZ_PROCESS_TIMEOUT.getRespCode())) {

                        /*更新对账不平交易表*/
                        updateManualReconErrTxn(traceNo, AdjustStatusEnum.OVERTIME.getJustStatus(), reconErrTxn);

                        /*添加差错调账流水*/
                        insertManualErrAdjustTxn(reconErrTxn, result.getResult().getRespCode(), result.getResult().getRespDesc(), traceNo, null, AcctStatusEnum.OVERTIME.getAcctStatus());

                        rglog.error("手工调账处理超时，instId:<{}>,instId:<{}>", instId, adjustUnionKey);
                        throw new BizException(OltpRpcdEnum.BIZ_PROCESS_TIMEOUT.getRespCode(), OltpRpcdEnum.BIZ_PROCESS_TIMEOUT.getRespDesc());

                    } else {

                        String respCode = result.getResult().getRespCode();
                        String respDesc = result.getResult().getRespDesc();
                        String seqNum = result.getResult().getAcctSeqNum();
                        String acctDate = result.getResult().getAcctDate();
                        String justStatus = (RespCodeEnum.TRANS_SUCCESS.getRespCode().equals(respCode)) ? AdjustStatusEnum.SUCCESS.getJustStatus() : AdjustStatusEnum.FAIL.getJustStatus();

                        manualAdjustmentResponse.setAcctStatus(justStatus);
                        manualAdjustmentResponse.setFailureReason(respDesc);
                        manualAdjustmentResponse.setAcctSeqNum(seqNum);
                        manualAdjustmentResponse.setAcctDate(acctDate);
                        manualAdjustmentResponse.setRespCode(respCode);
                        manualAdjustmentResponse.setRespDesc(respDesc);

                        /*更新对账不平交易表*/
                        updateManualReconErrTxn(traceNo, justStatus, reconErrTxn);

                        /*添加差错调账流水*/
                        String acctStatus = (RespCodeEnum.TRANS_SUCCESS.getRespCode().equals(respCode)) ? AcctStatusEnum.SUCCESS.getAcctStatus() : AcctStatusEnum.FAIL.getAcctStatus();
                        insertManualErrAdjustTxn(reconErrTxn, respCode, respDesc, traceNo, acctDate, acctStatus);

                    }
                    //未对账并且反向交易
                } else {

                    /*更新对账不平交易表*/
                    updateManualReconErrTxn(traceNo, AdjustStatusEnum.FAIL.getJustStatus(), reconErrTxn);

                    /*添加差错调账流水*/
                    insertManualErrAdjustTxn(reconErrTxn, null, null, traceNo, null, AcctStatusEnum.FAIL.getAcctStatus());

                    rglog.error("手工调账(调用duboo)处理失败，instId:<{}>,instId:<{}>", instId, adjustUnionKey);
                    throw new BizException(OltpRpcdEnum.CALL_BIZ_SERVICE_ERROR.getRespCode(), OltpRpcdEnum.CALL_BIZ_SERVICE_ERROR.getRespDesc());
                }

                /*反向交易*/
            } else if (AdjustTransactionTypeEnum.back.getTransactionType().equals(transactionType)) {

                /*调账不平表数据修改为调账中*/
                reconErrTxn.setAdjustStatus("01");
                ManualReconErrTxnMapper manualReconErrTxnMapper = new ManualReconErrTxnMapperImpl();
                int iReturnCode = manualReconErrTxnMapper.updateReconErrTxnByprimaryKey(reconErrTxn);
                if (0 != iReturnCode) {
                    throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
                }

                /*调用虚拟账户预授权完成接口*/
                VirtAcctPreAuthCompRequest virtAcctPreAuthCompRequest = new VirtAcctPreAuthCompRequest();

                virtAcctPreAuthCompRequest.setHeader(new Header());
                BeanUtil.beanCopy(manualAdjustmentRequest.getHeader(), virtAcctPreAuthCompRequest.getHeader());
                virtAcctPreAuthCompRequest.getHeader().setSrcSysId(ChannelEnum.BOMP.getChannelType());  //本系统标识
                virtAcctPreAuthCompRequest.getHeader().setChanlId(ChannelEnum.BOMP.getChannelType()); //渠道标识
                String traceNo = GlobalEsbUtil.generateEsbSeqeuenceNumber(manualAdjustmentRequest.getHeader().getInstId());
                virtAcctPreAuthCompRequest.getHeader().setTraceNo(traceNo); //流水号
                virtAcctPreAuthCompRequest.getHeader().setTxnNum("P06AT500"); //P06AT500
                virtAcctPreAuthCompRequest.getHeader().setBizType("00"); //业务分类

                virtAcctPreAuthCompRequest.setUserId(reconErrTxn.getMchntNo());
                virtAcctPreAuthCompRequest.setUserType("00");
                virtAcctPreAuthCompRequest.setAcctType("00");
                virtAcctPreAuthCompRequest.setTransAmt(reconErrTxn.getTransAmt());
                virtAcctPreAuthCompRequest.setFreezeAcctSeqNum(reconErrTxn.getPayChannelSeqNum());
                //虚拟账户预授权完成交易
                DubboService dubboService = new DubboServiceImpl();
                cc.rengu.igas.acct.facade.result.Result<VirtAcctPreAuthCompResponse> result = (cc.rengu.igas.acct.facade.result.Result<VirtAcctPreAuthCompResponse>) dubboService.callDubboService(DubboMethodConstant.DUBBO_VIRT_ACCT_SERVICE, "virtAcctPreAuthComp", virtAcctPreAuthCompRequest);
                if (result != null && result.isSuccess()) {
                    if (result.getResult().getRespCode().equals(OltpRpcdEnum.BIZ_PROCESS_TIMEOUT.getRespCode())) {

                        /*更新对账不平交易表*/
                        updateManualReconErrTxn(traceNo, AdjustStatusEnum.OVERTIME.getJustStatus(), reconErrTxn);

                        /*添加差错调账流水*/
                        insertManualErrAdjustTxn(reconErrTxn, result.getResult().getRespCode(), result.getResult().getRespDesc(), traceNo, null, AcctStatusEnum.OVERTIME.getAcctStatus());


                        rglog.error("调用虚拟账户预授权完成接口超时，instId:<{}>,instId:<{}>", instId, adjustUnionKey);
                        throw new BizException(OltpRpcdEnum.BIZ_PROCESS_TIMEOUT.getRespCode(), OltpRpcdEnum.BIZ_PROCESS_TIMEOUT.getRespDesc());
                    } else {

                        String respCode = result.getResult().getRespCode();
                        String respDesc = result.getResult().getRespDesc();
                        String seqNum = result.getResult().getAcctSeqNum();
                        String acctDate = result.getResult().getAcctDate();
                        String justStatus = (RespCodeEnum.TRANS_SUCCESS.getRespCode().equals(respCode)) ? AdjustStatusEnum.SUCCESS.getJustStatus() : AdjustStatusEnum.FAIL.getJustStatus();

                        manualAdjustmentResponse.setAcctStatus(justStatus);
                        manualAdjustmentResponse.setFailureReason(respDesc);
                        manualAdjustmentResponse.setAcctSeqNum(traceNo);
                        manualAdjustmentResponse.setAcctDate(acctDate);
                        manualAdjustmentResponse.setRespCode(respCode);
                        manualAdjustmentResponse.setRespDesc(respDesc);

                        /*更新对账不平交易表*/
                        updateManualReconErrTxn(traceNo, justStatus, reconErrTxn);

                        /*添加差错调账流水*/
                        String acctStatus = (RespCodeEnum.TRANS_SUCCESS.getRespCode().equals(respCode)) ? AcctStatusEnum.SUCCESS.getAcctStatus() : AcctStatusEnum.FAIL.getAcctStatus();
                        insertManualErrAdjustTxn(reconErrTxn, respCode, respDesc, traceNo, acctDate, acctStatus);

                    }
                    //未对账并且反向交易
                } else {

                    /*更新对账不平交易表*/
                    updateManualReconErrTxn(traceNo, AdjustStatusEnum.FAIL.getJustStatus(), reconErrTxn);

                    /*添加差错调账流水*/
                    insertManualErrAdjustTxn(reconErrTxn, null, null, traceNo, null, AcctStatusEnum.FAIL.getAcctStatus());

                    rglog.error("调用虚拟账户预授权完成接口失败，instId:<{}>,instId:<{}>", instId, adjustUnionKey);
                    throw new BizException(OltpRpcdEnum.CALL_BIZ_SERVICE_ERROR.getRespCode(), OltpRpcdEnum.CALL_BIZ_SERVICE_ERROR.getRespDesc());

                }
            } else {
                rglog.error("获取对账不平信息状态或交易类型不匹配，不允许发起调账请求，instId:<{}>,adjustUnionKey:<{}>,adjustStatus:<{}>,transactionType:<{}>", manualAdjustmentRequest.getHeader().getInstId(), adjustUnionKey, adjustStatus, transactionType);
                throw new BizException(RespCodeEnum.RECORD_NOT_FOUND.getRespCode(), RespCodeEnum.RECORD_NOT_FOUND.getRespDesc());
            }
        } else {
            rglog.error("获取对账不平信息状态或交易类型不匹配，不允许发起调账请求，instId:<{}>,adjustUnionKey:<{}>,adjustStatus:<{}>,transactionType:<{}>", manualAdjustmentRequest.getHeader().getInstId(), adjustUnionKey, adjustStatus, transactionType);
            throw new BizException(RespCodeEnum.RECORD_NOT_FOUND.getRespCode(), RespCodeEnum.RECORD_NOT_FOUND.getRespDesc());
        }
        return manualAdjustmentResponse;
    }

    /*
     *营销对账
     * @param manualAdjustmentRequest 请求
     * @param reconErrTxn             对账不平表
     * @throws Exception 异常
     */
    private ManualAdjustmentResponse marketing(ManualAdjustmentRequest manualAdjustmentRequest, ReconErrTxn reconErrTxn) throws Exception {
        String transactionType = reconErrTxn.getTxnNum().substring(1, 3);
        String adjustUnionKey = manualAdjustmentRequest.getAdjustUnionKey();
        String instId = manualAdjustmentRequest.getHeader().getInstId();
        String adjustStatus = reconErrTxn.getAdjustStatus();

        //对账结果是02（支付平台无，通道多 ）并且未调账的  02
        if ((ReconRsltEnum.RECONRSLT_09.getReconRslt().equals(reconErrTxn.getReconRslt()) || ReconRsltEnum.RECONRSLT_02.getReconRslt().equals(reconErrTxn.getReconRslt()))
                && (AdjustStatusEnum.INIT.getJustStatus().equals(adjustStatus) || AdjustStatusEnum.FAIL.getJustStatus().equals(adjustStatus))) {

            /*调账不平表数据修改为调账中*/
            ManualAdjustmentResponse manualAdjustmentResponse = new ManualAdjustmentResponse();
            reconErrTxn.setAdjustStatus(AdjustStatusEnum.IN.getJustStatus());
            ManualReconErrTxnMapper manualReconErrTxnMapper = new ManualReconErrTxnMapperImpl();
            int iReturnCode = manualReconErrTxnMapper.updateReconErrTxnByprimaryKey(reconErrTxn);
            if (0 != iReturnCode) {
                throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
            }

            /*调用营销调账接口*/
            /*报文头*/
            TxnDataRegulationRequest txnDataRegulationRequest = new TxnDataRegulationRequest();
            txnDataRegulationRequest.setHeader(new cc.rengu.igas.momp.facade.base.Header());
            BeanUtil.beanCopy(manualAdjustmentRequest.getHeader(), txnDataRegulationRequest.getHeader());
            txnDataRegulationRequest.getHeader().setSrcSysId(ChannelEnum.BOMP.getChannelType());                  //本系统标识
            txnDataRegulationRequest.getHeader().setChanlId(ChannelEnum.BOMP.getChannelType());         //渠道标识
            XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
            String traceNo = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.SYS_SEQ_NUM);
            txnDataRegulationRequest.getHeader().setTraceNo(traceNo); //流水号
            txnDataRegulationRequest.getHeader().setTxnNum("P08MO001");
            txnDataRegulationRequest.getHeader().setBizType("00"); //业务分类
            txnDataRegulationRequest.getHeader().setTransDate(DateUtil.getCurrentDateTime("yyyyMMdd"));
            txnDataRegulationRequest.getHeader().setTransTime(DateUtil.getCurrentDateTime("HHmmss"));

            /*数据*/
            TxnDataRegulationBean orderDetail = new TxnDataRegulationBean();
            /* 原交易日期 */
            orderDetail.setOrigTxnDate(reconErrTxn.getTransDate());
            /* 原交易流水号 */
            orderDetail.setOrigTraceNo(reconErrTxn.getPrimaryKey());
            /* 调账标志 */
            orderDetail.setRegulationFlag("1");
            txnDataRegulationRequest.setOrderDetail(orderDetail);

            /*调用duboo:PaymentService.txnDataRegulation*/
            DubboService dubboService = new DubboServiceImpl();
            cc.rengu.igas.momp.facade.result.Result<TxnDataRegulationResponse> result = (cc.rengu.igas.momp.facade.result.Result<TxnDataRegulationResponse>) dubboService.callDubboService("paymentService", "txnDataRegulation", txnDataRegulationRequest);

            /*业务返回为true*/
            if (result != null && result.isSuccess()) {
                TxnDataRegulationBean txnDataRegulationBean = result.getResult().getOrderDetail();

                /*业务超时*/
                if (result.getResult().getRespCode().equals(OltpRpcdEnum.BIZ_PROCESS_TIMEOUT.getRespCode())) {

                    /*更新对账不平交易表*/
                    updateManualReconErrTxn(traceNo, AdjustStatusEnum.OVERTIME.getJustStatus(), reconErrTxn);

                    /*添加差错调账流水*/
                    insertManualErrAdjustTxn(reconErrTxn, result.getResult().getRespCode(), result.getResult().getRespDesc(), traceNo, null, AcctStatusEnum.OVERTIME.getAcctStatus());

                    rglog.error("调用核心调账接口超时，instId:<{}>,instId:<{}>", instId, adjustUnionKey);
                    throw new BizException(OltpRpcdEnum.BIZ_PROCESS_TIMEOUT.getRespCode(), OltpRpcdEnum.BIZ_PROCESS_TIMEOUT.getRespDesc());

                } else {

                    String acctStatus = (RespCodeEnum.TRANS_SUCCESS.getRespCode().equals(result.getResult().getRespCode())) ? AdjustStatusEnum.SUCCESS.getJustStatus() : AdjustStatusEnum.FAIL.getJustStatus();
                    manualAdjustmentResponse.setRespCode(result.getResult().getRespCode());
                    manualAdjustmentResponse.setRespDesc(result.getResult().getRespDesc());
                    manualAdjustmentResponse.setAcctStatus(acctStatus);
                    manualAdjustmentResponse.setFailureReason(result.getResult().getRespDesc());
                    manualAdjustmentResponse.setAcctSeqNum(traceNo);
                    manualAdjustmentResponse.setAcctDate(txnDataRegulationBean.getOrigTxnDate());

                    /*更新对账不平交易表*/
                    updateManualReconErrTxn(traceNo, acctStatus, reconErrTxn);

                    /*添加差错调账流水*/
                    insertManualErrAdjustTxn(reconErrTxn, result.getResult().getRespCode(), result.getResult().getRespDesc(), traceNo, txnDataRegulationBean.getOrigTxnDate(), acctStatus);

                }

            } else {

                /*更新对账不平交易表*/
                updateManualReconErrTxn(traceNo, AdjustStatusEnum.FAIL.getJustStatus(), reconErrTxn);

                /*添加差错调账流水*/
                insertManualErrAdjustTxn(reconErrTxn, null, null, traceNo, null, AcctStatusEnum.FAIL.getAcctStatus());

                rglog.error("调用核心调账接口失败，instId:<{}>,instId:<{}>", instId, adjustUnionKey);
                throw new BizException(OltpRpcdEnum.BIZ_PROCESS_TIMEOUT.getRespCode(), OltpRpcdEnum.BIZ_PROCESS_TIMEOUT.getRespDesc());
            }
            return manualAdjustmentResponse;
        } else {
            rglog.error("获取对账不平信息状态或交易类型不匹配，不允许发起调账请求");
            throw new BizException(RespCodeEnum.RECORD_NOT_FOUND.getRespCode(), RespCodeEnum.RECORD_NOT_FOUND.getRespDesc());
        }

    }

    /*
     *银联全渠道代付
     * @param manualAdjustmentRequest 请求
     * @param reconErrTxn             对账不平表
     * @throws Exception 异常
     */
    private ManualAdjustmentResponse unionpayPartiallyRepay(ManualAdjustmentRequest manualAdjustmentRequest, ReconErrTxn reconErrTxn) throws Exception {

        ManualAdjustmentResponse manualAdjustmentResponse = new ManualAdjustmentResponse();
        String transactionType = reconErrTxn.getTxnNum().substring(1, 3);
        String adjustUnionKey = manualAdjustmentRequest.getAdjustUnionKey();
        String instId = manualAdjustmentRequest.getHeader().getInstId();
        String adjustStatus = reconErrTxn.getAdjustStatus();
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();

        //对账结果
        if (ReconRsltEnum.RECONRSLT_27.getReconRslt().equals(reconErrTxn.getReconRslt())) {

            /*调账不平表数据修改为调账中*/
            reconErrTxn.setAdjustStatus("01");
            ManualReconErrTxnMapper manualReconErrTxnMapper = new ManualReconErrTxnMapperImpl();
            int iReturnCode = manualReconErrTxnMapper.updateReconErrTxnByprimaryKey(reconErrTxn);
            if (0 != iReturnCode) {
                throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
            }

            /*调用核心调账接口*/
            String traceNo = GlobalEsbUtil.generateEsbSeqeuenceNumber(manualAdjustmentRequest.getHeader().getInstId());
            //TODO 调用核心调账
        }
        return manualAdjustmentResponse;
    }


    /*
     * 添加手工调账流水表
     * @param reconErrTxn
     * @param respCode 响应码
     * @param respDesc  响应描述
     * @param acctSeqNum 记账流水号
     * @param acctDate  记账日期
     * @param acctStatus 记账时间
     * @throws Exception
     */
    private void insertManualErrAdjustTxn(ReconErrTxn reconErrTxn, String respCode, String respDesc, String acctSeqNum, String acctDate, String acctStatus) throws Exception {
        /*添加差错调账流水*/
        ErrAdjustTxn errAdjustTxn = new ErrAdjustTxn();
        errAdjustTxn.setInstId(reconErrTxn.getInstId());
        errAdjustTxn.setBatchDate(reconErrTxn.getBatchDate());
        errAdjustTxn.setTransDate(DateUtil.getCurrentDateTime("yyyyMMdd"));
        errAdjustTxn.setTransTime(DateUtil.getCurrentDateTime("HHmmss"));
        errAdjustTxn.setPrimaryKey(reconErrTxn.getPrimaryKey());
        errAdjustTxn.setAcctTime(DateUtil.getCurrentDateTime("HHmmss"));
        errAdjustTxn.setRespCode(respCode);
        errAdjustTxn.setAcctSeqNum(acctSeqNum);
        errAdjustTxn.setAcctDate(acctDate);
        errAdjustTxn.setRespDesc(respDesc);
        errAdjustTxn.setAcctStatus(acctStatus);
        ManualErrAdjustTxnMapper manualErrAdjustTxnMapper = new ManualErrAdjustTxnMapperImpl();
        int dbResult = manualErrAdjustTxnMapper.insertErrAdjustTxn(errAdjustTxn);
        if (dbResult != 0) {
            rglog.error("登记差错调账流水失败,instId:<{}>,primaryKey:<{}>,iReturnCode:<{}>", errAdjustTxn.getInstId(), errAdjustTxn.getPrimaryKey(), dbResult);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }

    }

    /*
     * 更新手工调账
     * @param acctSeqNum
     * @param acctStatus     状态
     * @param reconErrTxn    手工调账
     * @throws Exception 异常
     */
    private void updateManualReconErrTxn(String acctSeqNum, String acctStatus, ReconErrTxn reconErrTxn) throws Exception {
        reconErrTxn.setRemark2(acctSeqNum);
        reconErrTxn.setAdjustStatus(acctStatus);
        ManualReconErrTxnMapper manualReconErrTxnMapper = new ManualReconErrTxnMapperImpl();
        int iReturnCode = manualReconErrTxnMapper.updateReconErrTxnByprimaryKey(reconErrTxn);
        if (0 != iReturnCode) {
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    private ManualAdjustmentResponse coreGeneralAcctTransferAndConsumeRefund(ManualAdjustmentRequest manualAdjustmentRequest, ReconErrTxn reconErrTxn) throws Exception {
        ManualAdjustmentResponse manualAdjustmentResponse = new ManualAdjustmentResponse();

        String status = manualAdjustmentRequest.getStatus();
        DubboService dubboService = new DubboServiceImpl();
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String traceNo = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.SYS_SEQ_NUM);
        PayOrderInfo payOrderInfo = new PayOrderInfo();

        //资金回退
        if (status.equals("1")) {
            PayOrderInfoMapper payOrderInfoMapper = new PayOrderInfoMapperImpl();
            List<PayOrderInfo> payOrderInfoList = payOrderInfoMapper.selectPayOrderInfoBySysSeqNum(reconErrTxn.getInstId(), reconErrTxn.getOrderId());
            List<PayOrderInfo> payOrderInfoListUpac = payOrderInfoList.stream().filter(item -> item.getMsgDstId().equals(ChannelEnum.UPTK.getChannelType())).sorted(Comparator.comparing(PayOrderInfo::getDstCallIndex)).collect(Collectors.toList());
            List<PayOrderInfo> payOrderInfoListEsb = payOrderInfoList.stream().filter(item -> item.getMsgDstId().equals(ChannelEnum.ESB.getChannelType())).sorted(Comparator.comparing(PayOrderInfo::getDstCallIndex)).collect(Collectors.toList());
            if (payOrderInfoListUpac.size() == 0) {
                rglog.error("此交易不支持，instId:<{}>,primaryKey:<{}>", reconErrTxn.getInstId(), reconErrTxn.getPrimaryKey());
                throw new BizException(OltpRpcdEnum.PARAM_IS_EMPTY_OR_NULL.getRespCode(), OltpRpcdEnum.PARAM_IS_EMPTY_OR_NULL.getRespDesc());
            }
            /*获取系统流水号*/
            String sysNum = xmlTreeUtil.getXmlTreeStringValue(TreeNodeConstant.SYS_SEQ_NUM);
            PayOrderInfo payOrderInfoEsb = payOrderInfoListEsb.get(0);
            payOrderInfo = payOrderInfoListUpac.get(0);
            cc.rengu.igas.channel.upac.facade.base.Header upacHeader = new cc.rengu.igas.channel.upac.facade.base.Header();
            upacHeader.setTxnNum("4000000902");
            upacHeader.setInstId(payOrderInfoEsb.getInstId());
            upacHeader.setTraceNo(sysNum);
            upacHeader.setChanlId(ChannelEnum.BOMP.getChannelType());
            upacHeader.setSrcSysId(AppParamConstant.SYS_ID);
            upacHeader.setBizType("00");
            upacHeader.setVersion("1.0.0");
            upacHeader.setTransTime(DateUtil.getCurrentTime());
            upacHeader.setTransDate(DateUtil.getCurrentDate());
            TokenConsumeRefundRequest tokenConsumeRefundRequest = new TokenConsumeRefundRequest();
            tokenConsumeRefundRequest.setHeader(upacHeader);
            tokenConsumeRefundRequest.setAccessType("0");
            tokenConsumeRefundRequest.setChannelType("07");
            tokenConsumeRefundRequest.setProdType("TK01");
            //tokenConsumeRefundRequest.setUpacMchntNo(upacMchntNo);

            tokenConsumeRefundRequest.setOrderAmt(reconErrTxn.getTransAmt());
            tokenConsumeRefundRequest.setOrderId(sysNum);
            tokenConsumeRefundRequest.setOrderTime(payOrderInfo.getTxnDate().concat(payOrderInfo.getTxnTime()));
            tokenConsumeRefundRequest.setOrigChannelSeqNum(payOrderInfo.getChannelSeqNum());
            String orderTime = payOrderInfo.getTxnDate().concat(payOrderInfo.getTxnTime());
            Object object = dubboService.callDubboService("upacTokenPayService", "tokenConsumeRefund", tokenConsumeRefundRequest);
            cc.rengu.igas.channel.upac.facade.result.Result<TokenConsumeRefundResponse> upacResult = (cc.rengu.igas.channel.upac.facade.result.Result<TokenConsumeRefundResponse>) object;
            if (upacResult != null && upacResult.isSuccess()) {

                String respCode = upacResult.getResult().getRespCode();
                String respMsg = upacResult.getResult().getRespDesc();
                String acctDate = DateUtil.getCurrentDateTime("yyyyMMdd");
                String justStatus = (RespCodeEnum.TRANS_SUCCESS.getRespCode().equals(respCode)) ? AdjustStatusEnum.SUCCESS.getJustStatus() : AdjustStatusEnum.FAIL.getJustStatus();

                manualAdjustmentResponse.setAcctStatus(justStatus);
                manualAdjustmentResponse.setFailureReason(respMsg);
                manualAdjustmentResponse.setAcctSeqNum(traceNo);
                manualAdjustmentResponse.setAcctDate(acctDate);
                manualAdjustmentResponse.setRespCode(respCode);
                manualAdjustmentResponse.setRespDesc(respMsg);

                /*更新对账不平交易表*/
                updateManualReconErrTxn(traceNo, AdjustStatusEnum.IN.getJustStatus(), reconErrTxn);

                /*添加差错调账流水*/
                String acctStatus = (RespCodeEnum.TRANS_SUCCESS.getRespCode().equals(respCode)) ? AcctStatusEnum.SUCCESS.getAcctStatus() : AcctStatusEnum.FAIL.getAcctStatus();
                insertManualErrAdjustTxn(reconErrTxn, respCode, respMsg, traceNo, acctDate, AcctStatusEnum.INIT.getAcctStatus());
                /*查询商户订单*/
                MchntOrderInfoMapper mchntOrderInfoMapper = new MchntOrderInfoMapperImpl();
                List<MchntOrderInfo> mchntOrderInfoList = mchntOrderInfoMapper.selectMchntOrderInfoBySysSeqNum(reconErrTxn.getInstId(), reconErrTxn.getOrderId());
                MchntOrderInfo mchntOrderInfo = mchntOrderInfoList.get(0);
                /*查询用户订单*/
                UserOrderInfoMapper userOrderInfoMapper = new UserOrderInfoMapperImpl();
                UserOrderInfo userOrderInfo = userOrderInfoMapper.selectUserOrderInfoByPrimaryKey(reconErrTxn.getInstId(), reconErrTxn.getOrderId());

                /*更新订单服务*/
                OrderService orderService = new OrderServiceImpl();
                //查询是否有资金回退的订单了
                List<PayOrderInfo> payOrderInfoLists = payOrderInfoMapper.selectPayOrderInfoByOrigSysSeqNum(reconErrTxn.getInstId(), reconErrTxn.getOrderId());
                List<PayOrderInfo> payOrderInfoListEsbs = payOrderInfoList.stream().filter(item -> item.getTxnNum().equals("P01BM001")).sorted(Comparator.comparing(PayOrderInfo::getDstCallIndex)).collect(Collectors.toList());
                if (payOrderInfoListEsbs.size() == 0) {

                    userOrderInfo.setTransStatus("0");
                    userOrderInfo.setBizStatus("01");
                    userOrderInfo.setCreateTime(DateUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss.SSS"));
                    userOrderInfo.setTxnDate(DateUtil.getCurrentDate());
                    userOrderInfo.setTxnTime(DateUtil.getCurrentTime());
                    userOrderInfo.setTxnNum("P01BM001");
                    userOrderInfo.setOrigSysSeqNum(userOrderInfo.getSysSeqNum());
                    userOrderInfo.setMchntOrderId(sysNum);
                    userOrderInfo.setSysSeqNum(sysNum);
                    //userOrderInfoMapper.insertUserOrderInfo(userOrderInfo);
                    userOrderInfo.setOrigTxnDate(orderTime);
                    String unionKey = manualAdjustmentRequest.getAdjustUnionKey().substring(0, 15);
                    BeanUtil.beanCopy(userOrderInfo, payOrderInfo);
                    payOrderInfo.setTxnNum("P01BM001");
                    payOrderInfo.setChannelBizType("0000");
                    payOrderInfo.setTransStatus("0");
                    payOrderInfo.setBizStatus("01");
                    payOrderInfo.setSettleDate(DateUtil.getCurrentDate());
                    payOrderInfo.setChannelReconKey(unionKey.concat(upacResult.getResult().getHeader().getTraceNo()));
                    payOrderInfo.setMsgDstId("UPAC");
                    payOrderInfo.setPayType("00");
                    rglog.info("==================交易时间" + orderTime);
                    payOrderInfo.setUserId("");
                    payOrderInfo.setDstChannelType("TK01");
                    payOrderInfo.setDstTxnNum("4000000902");
                    payOrderInfo.setRespCode(respCode);
                    payOrderInfo.setRespDesc(respMsg);
                    payOrderInfo.setPayerAcctInfo("");
                    payOrderInfo.setPayeeAcctInfo("");
                    payOrderInfo.setPayerAcctType("03");
                    payOrderInfo.setChannelSeqNum(upacResult.getResult().getChannelSeqNum());

                    //payOrderInfoMapper.insertPayOrderInfo(payOrderInfo);

                    BeanUtil.beanCopy(userOrderInfo, mchntOrderInfo);
                    //mchntOrderInfoMapper.insertMchntOrderInfo(mchntOrderInfo);
                    List<MchntOrderInfo> mchntOrderInfoLists = new ArrayList<>();
                    mchntOrderInfoLists.add(mchntOrderInfo);
                    orderService.registerOrderInfo(userOrderInfo, mchntOrderInfoList, payOrderInfo);
                }

            } else {

                /*更新对账不平交易表*/
                updateManualReconErrTxn(traceNo, AdjustStatusEnum.FAIL.getJustStatus(), reconErrTxn);

                /*添加差错调账流水*/
                insertManualErrAdjustTxn(reconErrTxn, null, null, traceNo, null, AcctStatusEnum.FAIL.getAcctStatus());

                rglog.error("调用核心调账接口失败，instId:<{}>,primaryKey:<{}>", reconErrTxn.getInstId(), reconErrTxn.getPrimaryKey());
                throw new BizException(OltpRpcdEnum.BIZ_PROCESS_TIMEOUT.getRespCode(), OltpRpcdEnum.BIZ_PROCESS_TIMEOUT.getRespDesc());

            }

            //二次入账
        } else if (status.equals("2")) {
            //TODO 调用核心记账
        }

        return manualAdjustmentResponse;
    }


}